<?php

class Str_Keyword
{
	public static $autofilterword = array();

	function replaceKeyword($varname, &$word)
	{
		if (!function_exists('mb_internal_encoding'))
		{
			return false;
		}
		
		Str_Keyword::loadKeyword($varname);
		$forbid = false;
		mb_internal_encoding("utf-8");
		foreach (self::$$varname as $keyword)
		{
			//echo "$keyword\n";
			//$keyword = iconv('gb2312', 'utf8//IGNORE', $keyword);

			if (false !== mb_strpos($word, $keyword))
			{
				$forbid = true;
				$starstr = "";
				for($i=0 ; $i<strlen($keyword) ; $i++)
				{
					$starstr .= "*";
				}
				$word = mb_ereg_replace($keyword, $starstr, $word);
			}
		}
		return $forbid;
	}

	function loadKeyword($varname)
	{
		if (empty(self::$$varname))
		{
			$filename = DATA_PATH . DS ."keyword". DS. $varname.".txt";
			$content = file_get_contents($filename);
			$fn_list = explode("\n", $content);
			foreach($fn_list as $fn)
			{
				$fn = trim($fn);
				if (strlen($fn) == 0)
				{
					continue;
				}
				array_push(self::$$varname, $fn);
			}
		}
	}
}
?>